<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: bobo
  Date: 16-11-1
  Time: 下午4:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <jsp:include page="../layout/head.jsp" >
        <jsp:param name="title" value="文章列表" />
    </jsp:include>

    <style>
        .table-list img {
            width: 70px;
            height: 50px;
        }
        .hide{
            display: none;
        }

    </style>
</head>
<body>

    <div class="panel admin-panel">
        <div class="panel-head"><strong class="icon-reorder"> 内容列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
        <div class="padding border-bottom">
            <ul class="search" style="padding-left:10px;">

                <li>
                    <input type="text" id="search" placeholder="请输入搜索关键字" value="${like}"  class="input" style="width:250px; line-height:17px;display:inline-block" />
                    <a href="javascript:void(0)" class="button border-main icon-search" id="search_btn" > 搜索</a>
                </li>
            </ul>
        </div>
        <table class="table table-hover text-center">
            <tr id="table-header">
                <th class="js-id"><a href="">ID</a>
                    <i class="${sort=='desc'? 'icon-caret-down' :'icon-caret-up'} ${sortName == 'id' ? '':'hide'}"></i>
                </th>
                <th>缩略图</th>
                <th>名称</th>
                <th>作者</th>
                <th>类别</th>
                <th class="js-hits"><a href="">点击量</a>
                    <i class="${sort=='desc'? 'icon-caret-down' :'icon-caret-up'} ${sortName == 'hits' ? '':'hide'}"></i>
                </th>
                <th class="js-favourites"><a href="">收藏量</a>
                    <i class="${sort=='desc'? 'icon-caret-down' :'icon-caret-up'} ${sortName == 'favourites' ? '':'hide'}"></i>
                </th>
                <th class="js-messages"><a href="">回帖数</a>
                    <i class="${sort=='desc'? 'icon-caret-down' :'icon-caret-up'} ${sortName == 'messages' ? '':'hide'}"></i>
                </th>
                <th class="js-create_time"><a href="">创建时间</a>
                    <i class="${sort=='desc'? 'icon-caret-down' :'icon-caret-up'} ${sortName == 'createTime' ? '':'hide'}"></i>
                </th>
                <th class="js-update_time"><a href="">修改时间</a>
                    <i class="${sort=='desc'? 'icon-caret-down' :'icon-caret-up'} ${sortName == 'updateTime' ? '':'hide'}"></i>
                </th>
                <th class="js-status"><a href="">状态</a>
                    <i class="${sort=='desc'? 'icon-caret-down' :'icon-caret-up'} ${sortName == 'status' ? '':'hide'}"></i>
                </th>
                <th>操作</th>
            </tr>

            <c:forEach items="${page.list}" var="topic">

                <tr class="table-list">
                    <td>${topic.id}</td>
                    <td><img src="${pageContext.request.contextPath}${topic.img}" alt=""></td>
                    <td><a href="${pageContext.request.contextPath}/admin/topic/get?id=${topic.id}">${topic.title}</a></td>
                    <td>${topic.username}</td>
                    <td>${topic.category}</td>
                    <td>${topic.hits}</td>
                    <td>${topic.favourites}</td>
                    <td>${topic.messages}</td>
                    <td>${topic.createTime}</td>
                    <td>${topic.updateTime}</td>
                    <td>
                        <%--状态 0禁用 1启用 2用户已删除 3未通过--%>
                        <c:if test="${topic.status ==0}">待审核</c:if>
                        <c:if test="${topic.status ==1}">通过</c:if>
                        <c:if test="${topic.status ==2}">用户已删除</c:if>
                        <c:if test="${topic.status ==3}">未通过</c:if>

                    </td>
                    <td>
                        <div class="button-group">
                            <c:if test="${topic.status==0}">
                                <a class="button border-main" href="javascript:void(0)" onclick="tg(${topic.id})">
                                    <span class="icon-glass">通过</span>
                                </a>
                            </c:if>
                            <c:if test="${topic.status==1 || topic.status==3 }">
                                <a class="button border-main" href="javascript:void(0)" disabled  onclick="tg(${topic.id})">
                                    <span class="icon-glass">通过</span>
                                </a>
                            </c:if>
                            <c:if test="${topic.status==2 || topic.status==1 || topic.status==3}">
                                <a class="button border-red" href="javascript:void(0)" disabled onclick="wtg(${topic.id})">
                                    <span class="icon-trash-o">未通过</span>
                                </a>
                            </c:if>
                            <c:if test="${topic.status==0}">
                                <a class="button border-red" href="javascript:void(0)" onclick="wtg(${topic.id})">
                                    <span class="icon-trash-o">未通过</span>
                                </a>
                            </c:if>

                        </div>
                    </td>
                </tr>

            </c:forEach>



                <tr>
                    <td colspan="12">
                        <jsp:include page="../layout/pager.jsp" >
                            <jsp:param name="pageNum" value="${page.pageNum}" />
                            <jsp:param name="current" value="${page.current}" />
                            <jsp:param name="pageSize" value="${page.pageSize}" />
                            <jsp:param name="url" value="${pageContext.request.contextPath}/admin/topic/getTopics" />
                        </jsp:include>

                    </td>
                </tr>
        </table>
    </div>

<script type="text/javascript">

    $(function () {


        var sort = '${sort}';
        var sortName = '${sortName}';
        var like = '${like}';

        var url = "${pageContext.request.contextPath}/admin/topic/getTopics?pageSize=${page.pageSize}&current=${page.current}";



        $("#table-header").find("th").each(function () {

                var _this = $(this);

            var _url = url;

                if(_this.attr("class")) {
                    _url += "&sortName="+_this.attr("class").replace("js-",'');
                    _url += "&sort="+ (sort == 'desc'?'ASC':'desc');
                    if(like) {
                        _url += "&like="+like;
                    }
                    _this.find("a").attr("href", _url);
                }


        });

        $("#search_btn").click(function () {
            var _search =  $("#search").val();
            var _url = "${pageContext.request.contextPath}/admin/topic/getTopics?pageSize=${page.pageSize}&current=1";

             if(sortName) {
                 _url += "&sortName="+ sortName;
             }

            _url += "&sort="+ (sort == 'desc'?'ASC':'desc');

            _url += "&like="+_search;


            window.location.href = _url;


        })


    });

    function tg(id) {
        $.ajax({
            url:"${pageContext.request.contextPath}/admin/topic/opee",
            type:"get",
            data:{"id":id,"status":1},
            success:function (dd) {
                if(dd=="true"){
                    alert("操作成功");
                    window.location.reload();
                }
            },
            error:function () {
                alert("操作失败");
            }
        })
    }

    function wtg(id) {
        var name = prompt("请输入未通过理由");
        $.ajax({
            url:"${pageContext.request.contextPath}/admin/topic/opee",
            type:"get",
            data:{"id":id,"status":3,"review":name},
            success:function (dd) {
                if(dd=="true"){
                    alert("操作成功");
                    window.location.reload();
                }
            },
            error:function () {
                alert("操作失败");
            }
        })
    }
</script>

</body>
</html>
